/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.lottery.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.lottery.entity.Participation;
import com.thinkgem.jeesite.modules.lottery.dao.ParticipationDao;

/**
 * 微信抽奖助手-用户参与情况Service
 *
 * @author 黄茂展
 * @version 2019-07-31
 */
@Service
@Transactional(readOnly = true)
public class ParticipationService extends CrudService<ParticipationDao, Participation> {

    @Autowired
    private ParticipationDao participationDao;

    public Participation get(String id) {
        return super.get(id);
    }

    public List<Participation> findList(Participation participation) {
        return super.findList(participation);
    }

    public Page<Participation> findPage(Page<Participation> page, Participation participation) {
        return super.findPage(page, participation);
    }

    public int getNumOfActivity(String openid) {
        return participationDao.getNumOfActivity(openid);
    }

    public int getUserNumOfPrize(String openid) {
        return participationDao.getUserNumOfPrize(openid);
    }

    public Participation getUserParticipation(String openid, String activityId) {
        return participationDao.getUserParticipation(openid, activityId);
    }

    public int getNumOfWechatUser(String activityId) {
        return participationDao.getNumOfWechatUser(activityId);
    }

    public List<String> getWechatUserImageOfActivity(String activityId) {
        return participationDao.getWechatUserImageOfActivity(activityId);
    }

    public List<String[]> getPrizeNicknameImageOfActivity(String activityId) {
        Map<String,String> map=participationDao.getPrizeNicknameImageOfActivity(activityId);
        List<String[]> result = new ArrayList<>();
        for(Map.Entry<String,String> entry :map.entrySet()){
            String[] strings = new String[2];
            strings[0]=entry.getKey();
            strings[1]=entry.getValue();
            result.add(strings);
        }
        return result;
    }

    public Participation getParticipationByOpenidActivityId(String openid,String activityId){
        Map<String,String> map=new HashMap<>();
        map.put("openid",openid);
        map.put("activityId",activityId);
        return participationDao.getParticipationByOpenidActivityId(map);
    }

    @Transactional(readOnly = false)
    public void save(Participation participation) {
        super.save(participation);
    }

    @Transactional(readOnly = false)
    public void delete(Participation participation) {
        super.delete(participation);
    }

}